Skip to content

ir-gen: Fix ICE when reading an indexed ref mut array element#7644

Open
Dnreikronos wants to merge 3 commits into
FuelLabs:masterfrom
Dnreikronos:fix/index-read-ref-mut-array-7602
Open

ir-gen: Fix ICE when reading an indexed ref mut array element#7644
Dnreikronos wants to merge 3 commits into
FuelLabs:masterfrom
Dnreikronos:fix/index-read-ref-mut-array-7602

Conversation

@Dnreikronos
Copy link
Copy Markdown
Contributor

Closes #7602

Reading an element of a ref mut array argument, like self[i] inside an impl ... for [T; N] method, crashed the compiler. A ref mut argument is already a pointer in IR, and the argument gets stored into a local on entry, so by the time the index-read code runs the prefix is a pointer to a pointer to the array. That shape wasn't handled and fell into a todo!(). Writing through the same self[i] worked because the reassignment path already dereferences ref mut arguments.

The index-read path now peels off the extra pointer indirection before indexing, the way reassignment does, and the previously disabled assert_eq(self[i], default) line in the const-generics reassignment test is back on.

A `ref mut` array argument is a pointer in IR, and storing it into a
local adds another level of indirection, so the index-read path saw a
pointer to a pointer to the array and aborted with `todo!()`. Peel the
extra pointer levels before indexing, matching how the reassignment
path already dereferences `ref mut` arguments.

Closes FuelLabs#7602
@Dnreikronos Dnreikronos requested a review from a team as a code owner May 28, 2026 20:22
@fuel-cla-bot
Copy link
Copy Markdown

fuel-cla-bot Bot commented May 28, 2026

Thanks for the contribution! Before we can merge this, we need @Dnreikronos to sign the Fuel Labs Contributor License Agreement.

@cursor
Copy link
Copy Markdown

cursor Bot commented May 28, 2026

PR Summary

Low Risk
Localized IR indexing fix with a regression test; no auth, runtime, or broad API surface changes.

Overview
Fixes a compiler ICE when reading an indexed element on a ref mut array (e.g. self[i] in impl ... for [T; N]), where the IR prefix was a pointer-to-pointer and indexing hit a todo!().

compile_indexing now loads through extra pointer layers until the prefix points at the real array/slice, matching the reassignment path. Unsupported pointer shapes return an internal compile error instead of panicking.

The const-generics reassignment e2e test re-enables assert_eq(self[i], default) now that reads compile.

Reviewed by Cursor Bugbot for commit b863ab9. Bugbot is set up for automated code reviews on this repo. Configure here.

@Dnreikronos
Copy link
Copy Markdown
Contributor Author

@ironcev, can we re-trigger the cla pipe here and on the other PRs that I have open?

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jun 1, 2026

Merging this PR will not alter performance

✅ 25 untouched benchmarks


Comparing Dnreikronos:fix/index-read-ref-mut-array-7602 (b7bcec1) with master (cf225be)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler ICE when accessing self[i] where self is defined using const generics [T;N]

1 participant